package net.gazhi.delonix.grac.web.controller;

import org.springframework.web.servlet.ModelAndView;

import net.gazhi.delonix.core.service.DataAccessDeniedException;
import net.gazhi.delonix.core.service.ValidationFaildException;
import net.gazhi.delonix.core.web.AbstractAnnotationController;
import net.gazhi.delonix.grac.web.controller.pub.ErrorPageController;

public class AbstractGracController extends AbstractAnnotationController {

	/**
	 * 处理 Service 中出现的 RuntimeException
	 * 
	 * @param e
	 */
	public ModelAndView handleServiceException(RuntimeException e) {
		// 验证失败，抛出异常，确保事务回滚，后续提示又具体的 Controller 决定
		if (e instanceof ValidationFaildException) {
			e.printStackTrace();
			return null;
		}
		// 无权访问数据，forward 到提示页面
		if (e instanceof DataAccessDeniedException) {
			e.printStackTrace();
			return new ModelAndView("forward:" + ErrorPageController.PAGE_DATA_ACCESS_DEINED);
		}
		// 其他异常，直接抛出，有容器处理
		throw e;
	}
}
